package com.app.qbake.module.mine.activity;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;

import com.netease.nim.uikit.api.NimUIKit;
import com.netease.nim.uikit.config.LogoutHelper;
import com.wind.base.BaseActivity;
import com.wind.base.repo.ConfigRepo;
import com.wind.base.utils.ActivityUtil;
import com.wind.base.utils.Navigator;
import com.wind.data.mine.FeedbackRequest;
import com.app.qbake.R;
import com.app.qbake.module.mine.event.LogoutEvent;
import com.app.qbake.module.mine.layout.LogoutLayout;
import com.app.qbake.util.AppDialogHelper;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import butterknife.ButterKnife;
import butterknife.OnClick;

public class SettingsActivity extends BaseActivity {
    public static void start(Context context){
        Navigator.navigate(context,SettingsActivity.class);
    }
    private LogoutLayout mLogoutLayout;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EventBus.getDefault().register(this);
        setContentView(R.layout.mu_activity_settings);
        ButterKnife.bind(this);
        mLogoutLayout=new LogoutLayout(getActivity());
    }

    @Override
    protected void setTitle() {
        mTitleBar.setTitle("设置");
    }

    @OnClick({R.id.tv_logout,R.id.layout_feedback,R.id.layout_aboutus,R.id.layout_service})
    public void onViewClick(View view){
        switch (view.getId()){
            case R.id.layout_service:
                NimUIKit.startP2PSession(getActivity(), ConfigRepo.getInstance().get(getActivity()).getIm_service());
                break;
            case R.id.layout_aboutus:
                AboutUsActivity.start(getActivity());
                break;
            case R.id.layout_feedback:
                FeedbackActivity.ExtraInfo info=new FeedbackActivity.ExtraInfo();
                info.type= FeedbackRequest.TYPE_FEEDBACK;
                FeedbackActivity.start(getActivity(),info);
                break;
            case R.id.tv_logout:
                AppDialogHelper.showNormalDialog(getActivity(), "确认退出登录吗？", new AppDialogHelper.DialogOperCallback() {
                    @Override
                    public void onDialogConfirmClick() {
                        mLogoutLayout.logout();
                    }
                });
                break;
        }
    }

    @Subscribe
    public void on(LogoutEvent event){
        LogoutHelper.logout();
        ActivityUtil.finish(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mLogoutLayout.onDestroy();
        EventBus.getDefault().unregister(this);
    }
}
